package org.kaleido.client.activity.mapper;

import org.kaleido.client.ClientFactory;
import org.kaleido.client.activity.AdminMenuActivity;
import org.kaleido.client.activity.EditLogActivity;
import org.kaleido.client.activity.ListLogDataActivity;
import org.kaleido.client.activity.NewLogActivity;
import org.kaleido.client.place.AdminMenuPlace;
import org.kaleido.client.place.EditLogPlace;
import org.kaleido.client.place.ListDataLogsPlace;
import org.kaleido.client.place.NewLogPlace;

import com.allen_sauer.gwt.log.client.Log;
import com.google.gwt.activity.shared.AbstractActivity;
import com.google.gwt.activity.shared.Activity;
import com.google.gwt.activity.shared.ActivityMapper;
import com.google.gwt.place.shared.Place;

/**
 * Mapper de actividades. Se encarga de generar la actividar (presenter) a partir del Place recibido, al cual se ha ido
 * medainte el controlador.
 */
public class InfoLogPanelActivityMapper implements ActivityMapper {

    /**
     * Factoria.
     */
    private final ClientFactory clientFactory;

    /**
     * Contructor a partir de la factoria.
     */
    public InfoLogPanelActivityMapper(ClientFactory clientFactory) {
        this.clientFactory = clientFactory;
    }

    /**
     * Proporcioan la 'actividad'/presenter asociado al place recibido.
     */
    public Activity getActivity(final Place place) {
        Log.debug("Accediendo a la pagina " + place);
        AbstractActivity activity = null;
        if (place instanceof NewLogPlace) {
            activity = new NewLogActivity(clientFactory);
        } else if (place instanceof EditLogPlace) {
            activity = new EditLogActivity(clientFactory);
        } else if (place instanceof AdminMenuPlace) {
            activity = new AdminMenuActivity(clientFactory);
        } else {
            activity = new ListLogDataActivity(clientFactory);
        } 
        return activity;
    }
}
